#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const int N = 1000001;
int pre[N + 1], suf[N + 1];

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    int M = 0;
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        suf[a[i]]++;
        M = max(a[i], M);
    }
    ll ans = 0;
    for(auto x : a) {
        suf[x]--;
        for(int y = 1; y <= x && y * x <= M; y++){
            ans += (ll)pre[y] * suf[x * y];
        }
        pre[x]++;
    }
    cout << ans << '\n';
    for(int x : a) {
        suf[x] = pre[x] = 0;
    }
}

int main() {
    int t;
    cin >> t;
    while(t --) solve();
    return 0;
}